<?php if(!defined('ARCH_ROOT_PATH')) exit;
/**
 *	Architect Framework
 *
 *	Architect Framework is a light weight object oriented web applications framework written for PHP 5.1.4 and later that provide the tools to develop and deploy a website or application fast and with as little code as possible.
 *
 *	@author Robin Grass, <hello@coffinboy.se>
 *	@link http://architect.kodlabbet.net
 *	@license http://www.opensource.org/licenses/gpl-3.0.html GNU General Public License (v. 3)
 */

/**
 *	Architect_FilterManager
 *
 *	This class holds and invokes custom filters.
 *
 *	@package Utilities
 *	@version 1.0
 *	@author Robin Grass, <hello@coffinboy.se>
 */
class Architect_FilterManager {

	/**
	 *	@var array $filters
	 */
	protected $filters = array();
	
	/**
	 *	hasFilter
	 *
	 *	@param string $filter
	 *
	 *	@return bool
	 */
	protected function hasFilter($filter) {
		return (array_key_exists($filter, $this->filters));
	}
	
	/**
	 *	setFilter
	 *
	 *	@param string $filter
	 *	@param object $obj
	 */
	protected function setFilter($filter, $obj) {
		$this->filters[$filter] = $obj;
	}
	
	/**
	 *	getFilter
	 *
	 *	@param string $filter
	 *
	 *	@return object
	 */
	protected function getFilter($filter) {
		if(!$this->hasFilter($filter))
			throw new InvalidArgumentException('Filter does not exist in registry.');
	return $this->filters[$filter];
	}
	
	/**
	 *	register
	 *
	 *	@param object $obj
	 *	@param string $filter
	 */
	public function register($obj, $filter) {
		if(!$this->hasFilter($filter))
			$this->setFilter($filter, $obj);
	}
	
	/**
	 *	__call
	 */
	private function __call($filter, $args) {
		return call_user_func_array(array($this->getFilter($filter), 'filter'), $args);
	}

}
?>